<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>资金申请</title>
</head>

<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="../app/index.do"></a>
			</div>
			<div class="header-title">资金申请列表</div>
		</div>

	</div>
	<div class="table-container" data-options="region:'center'">
		<div>
			<table id="pro_table" class="easyui-datagrid" style="min-height: 100%">
			</table>
			<div id="pro_tb" class="search-show">
				<div class="search-input">
					<span>项目：</span>
					<span>
						<input style="width: 100%;" id="projectitemid" name="projectitemid" class="easyui-combobox"
							editable="false"
							data-options="
							    valueField: 'id',
							    textField: 'name',
							    url: '../projectitemlist.do?status=2',
							    onLoadSuccess : function(data){ 
								   	if(data.length>0){
								    	$('#projectitemid').combobox('setValue',data[0].id);
							    	}
							    },onSelect: function(rec){
						    		projectitemid = rec.id;
							    	if(rec.projectitemchilds.length>0){
										var url = '../projectitemchildlist?status=2&&projectitemid=' + rec.id;
										$('#projectitemchildid').combobox('reload', url);
										document.getElementById('div1').style.display = '';
							    	}else{
							    		projectitemid = rec.id;
							    		projectitemchildid = 0;
										$('#projectitemchildid').combobox('clear');
										document.getElementById('div1').style.display = 'none';
								    	loadData();
							    	}
							    },panelHeight: 'auto'">
					</span>
				</div>
				<div id="div1" style="display: none;" class="search-input">
					<span>子项目：</span>
					<span>
						<input style="width: 100%;" id="projectitemchildid" name="projectitemchildid" class="easyui-combobox"
							editable="false"
							data-options="
							    valueField: 'id',
							    textField: 'name',
							    loadFilter: function (data) {
							        var obj = {};
							        obj.id = '';
							        obj.name = '全部';
							        data.splice(0, 0, obj);
							        return data;
							    },
							    onSelect: function(rec){
							    	projectitemchildid = rec.id;
							    	loadData();
							    },panelHeight: 'auto'">
					</span>
				</div>
				<div class="search-input">
					<span>状态：</span>
					<span>
						<select id="status" class="easyui-combobox" name="status" style="width: 100%;" editable="false"
							data-options="
							    onSelect: function(rec){
							   		status=rec.value;
							   		if(isnew){
							   			isnew = false;
							   		}else{
							   			loadData();
							   		}
							   		
							    },panelHeight: 'auto'">
							<option value="">全部</option>
							<option value="3">已拒绝</option>
							<option value="4">已审</option>
							<option value="6">待二级审核</option>
							<option value="7">待一级审核</option>
						</select>
					</span>
				</div>
				<div class="search-input text-right">
					<a href="javascript:void(0)" class="d-btn btn-blue" onclick="newpro()">添加</a>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
	var currentPro;
	var projectitemid;
	var projectitemchildid;
	var status;
	var isnew = true;
	function loadData() {
		if (projectitemchildid > 0){
			$('#pro_table').datagrid({
				rownumbers : true,
				singleSelect : true,
				pagination : true,
				fitColumns : false,
				border : false,
				striped : true,
				toolbar : '#pro_tb',
				url : "../capitalApply.do",
				method : 'get',
				queryParams : {
					projectitemchildid : projectitemchildid,
					status : status
				},
				onSelect : function(index,row) {
					currentPro = row;
				},
				columns : [ [ {
					field : 'projectitemname',
					title : '项目名称',
					width : '',
					formatter : function(value,row,index) {
						var html = '';
						html += '<div class="info-unreviewed">'
						if (row.projectitemchild){
							html += '<div class="info-item-name" style="width:'+ ellipsis(60) +'px;margin-bottom:10px;">' + row.projectitemchild.name + '</div>'
						}else{
							html += '<div class="info-item-name" style="width:'+ ellipsis(60) +'px;margin-bottom:10px;">' + row.item.name + '</div>'
						}
						html += '<div class="info-item-content" style="width:'+ ellipsis(0) +'px;">' + row.name + '</div>'
						html += '<div class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.content + '</div>'
						if(row.status == 3){
							html+='<div class="info-reason">' + row.reason + '</div>'
							html += '<div class="info-money c-grey">￥' + row.money + '</div>'
						}else{
							html += '<div class="info-money">￥' + row.money + '</div>'
						}
					if (row.status == 4){
						html += '<div class="info-status ok">已审</div><div class="edit"><span class="info-edit" onclick="updatepro('+index+')"></span></div>';
					}
					if (row.status == 3){
						html += '<div class="info-status c-grey">已拒绝</div><div class="edit"><span class="info-edit" onclick="updatepro('+index+')"></span></div>';
					}
					if (row.status == 6){
						html += '<div class="info-status two">待二级审核</div><div class="edit"><span class="info-edit" onclick="updatepro('+index+')"></span><span class="info-delete" onclick="deletepro('+index+')"></span></div>';
					}
					if (row.status == 7){
						html += '<div class="info-status one">待一级审核</div><div class="edit"><span class="info-edit" onclick="updatepro('+index+')"></span><span class="info-delete" onclick="deletepro('+index+')"></span></div>';
					}
					html += '</div>';
						return html;
					}
				} ] ]
			});
		}else{
			$('#pro_table').datagrid({
				rownumbers : true,
				singleSelect : true,
				pagination : true,
				fitColumns : false,
				border : false,
				striped : true,
				toolbar : '#pro_tb',
				url : "../capitalApply.do",
				method : 'get',
				queryParams : {
					projectitemid : projectitemid,
					status : status
				},
				onSelect : function(index,row) {
					currentPro = row;
				},
				columns : [ [ {
					field : 'projectitemname',
					title : '项目名称',
					width : '',
					formatter : function(value,row,index) {
						var html = '';
						html += '<div class="info-unreviewed">'
							if (row.projectitemchild){
								html += '<div class="info-item-name" style="width:'+ ellipsis(60) +'px;margin-bottom:10px;">' + row.projectitemchild.name + '</div>'
							}else{
								html += '<div class="info-item-name" style="width:'+ ellipsis(60) +'px;margin-bottom:10px;">' + row.item.name + '</div>'
							}
							html += '<div class="info-item-content" style="width:'+ ellipsis(0) +'px;">' + row.name + '</div>'
							html += '<div class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.content + '</div>'
							if(row.status == 3){
								html+='<div class="info-reason">' + row.reason + '</div>'
								html += '<div class="info-money c-grey">￥' + row.money + '</div>'
							}else{
								html += '<div class="info-money">￥' + row.money + '</div>'
							}
						if (row.status == 4){
							html += '<div class="info-status ok">已审</div><div class="edit"><span class="info-edit" onclick="updatepro('+index+')"></span></div>';
						}
						if (row.status == 3){
							html += '<div class="info-status c-grey">已拒绝</div><div class="edit"><span class="info-edit" onclick="updatepro('+index+')"></span></div>';
						}
						if (row.status == 6){
							html += '<div class="info-status two">待二级审核</div><div class="edit"><span class="info-edit" onclick="updatepro('+index+')"></span><span class="info-delete" onclick="deletepro('+index+')"></span></div>';
						}
						if (row.status == 7){
							html += '<div class="info-status one">待一级审核</div><div class="edit"><span class="info-edit" onclick="updatepro('+index+')"></span><span class="info-delete" onclick="deletepro('+index+')"></span></div>';
						}
						html += '</div>';
						return html;
					}
				} ] ]
			});
		}
		if (status != "" && status != 3){
			$('#pro_table').datagrid('hideColumn', 'reason');
		}
	}
	function ellipsis(value){
		var WIDTH = $("body").width();
		WIDTH-=10;
		var width;
		width = WIDTH-value
		return width;
	}
	function newpro() {
		window.location.href = "../app/capitalapplyadd.do";
	}
	function updatepro(index) {
		var item = $("#pro_table").datagrid('getRows')[index];
		window.location.href = "../app/capitalapplyadd.do?id=" + item.id;
	}
	function deletepro(index) {
		currentPro = $("#pro_table").datagrid('getRows')[index];
		if (currentPro){
			if (currentPro.status == 6){
				$.messager.confirm("操作提示", "您确定要执行操作吗？", function(data) {
					if (data){
						$.ajax({
							type : 'POST',
							url : "../capitalApplyRemove.do?id=" + currentPro.id,
							contentType : "application/json",
							success : function(data) {
								if (data.success){
									$.messager.show({
										title : '删除',
										msg : '删除成功',
										timeout : 5000,
										showType : 'slide'
									});
									loadData();
								}else{
									$.messager.alert('删除', '删除失败', 'error');
									loadData();
								}
							},
							dataType : "json"
						});
					}
				});
			}else{
			}
		}else{
			$.messager.alert('删除', '请选择要删除的资金申请', 'warning');
		}
	}
</script>
</html>